#include "app_buffer.h"
#include "log/log.h"

int main(int argc, char const *argv[])
{
    // unsigned char c = 128;
    // int d = c;
    // log_debug("d=%d", d);

    // Buffer *buffer0 = app_buffer_init(1024);
    // char data[255];
    // for (int i = 0; i < 255; i++)
    // {
    //     data[i] = 'a';
    // }
    // app_buffer_write(buffer0, data, 255);

    // char data2[300];
    // int len = app_buffer_read(buffer0, data2, 300);
    // log_debug("读数据：%.*s, len=%d", len, data2, len);
    




    // 初始化缓冲区
    Buffer *buffer = app_buffer_init(16);
    // 写入数据1
    app_buffer_write(buffer, "abcd", 4);
    // 写入数据2
    app_buffer_write(buffer, "efghi", 5);

    // 读取数据1
    char data_buf[5];
    int data_len = app_buffer_read(buffer, data_buf, sizeof(data_buf));
    log_debug("读数据1：%.*s, data_len=%d", data_len, data_buf, data_len);
    // 读取数据2
    char data_buf2[10];
    int data_len2 = app_buffer_read(buffer, data_buf2, sizeof(data_buf2));
    log_debug("读数据2：%.*s, data_len=%d", data_len2, data_buf2, data_len2);

    // 读取数据3 => 现在缓冲区是空的
    char data_buf3[10];
    int data_len3 = app_buffer_read(buffer, data_buf3, sizeof(data_buf3));
    log_debug("读数据3：%.*s, data_len=%d", data_len3, data_buf3, data_len3);

    // 写入数据3 =》 长度超过缓冲区总大小
    app_buffer_write(buffer, "12345678901234567890", 20);

    // 释放缓冲区
    app_buffer_free(buffer);

    return 0;
}
